package com.fadadianqi.logistics.sell.dao.ibatis;

import com.fadadianqi.commons.GenericDAOSuport;
import com.fadadianqi.logistics.sell.dao.PaymentDAO;
import com.fadadianqi.logistics.sell.model.Payment;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component("paymentDAO")
public class PaymentDAOImpl extends GenericDAOSuport<String, Payment> implements
        PaymentDAO {

    @Override
    protected Class<?> getObjectClass() {
        return Payment.class;
    }

    @Override
    protected String getTableName() {
        return "payment";
    }

    @Override
    public double sumPaid(String billId) {
        Object sum = getSqlMapClientTemplate().queryForObject(getNamespace() + ".sumPaid", billId);
        if (sum != null) {
            return (Double) sum;
        } else {
            return 0D;
        }
    }

    @Override
    public List<Payment> findByBillId(String billId) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("billId", billId);
        return super.findByPropertys(map);
    }

}
